import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/card/hirunWaterCard/list',
  save = '/card/hirunWaterCard/add',
  edit = '/card/hirunWaterCard/edit',
  get = '/card/hirunWaterCard/queryById',
  delete = '/card/hirunWaterCard/delete',
  importExcel = '/card/hirunWaterCard/importExcel',
  exportXls = '/card/hirunWaterCard/exportXls',
  exportXlsTemplate = '/card/hirunWaterCard/getImportTemplate',
  deleteBatch = '/card/hirunWaterCard/deleteBatch',
  addWhiteList = '/card/hirunWaterCard/addWhiteList',
  removeBlackList = '/card/hirunWaterCard/removeBlackList',
  removeWhiteList = '/card/hirunWaterCard/removeWhiteList',
  reportTheLossOfCard = '/card/hirunWaterCard/reportTheLossOfCard',
  releaseReportTheLossOfCard = '/card/hirunWaterCard/releaseReportTheLossOfCard',
  addBlackList = '/card/hirunWaterCard/addBlackList',
}
/**
 * 导出api
 */
export const getExportUrl = Api.exportXls;

export const getExportXlsTemplateUrl = Api.exportXlsTemplate;

export const getImportUrl = Api.importExcel;
/**
 * 查询列表
 * @param params
 */
export const getPositionList = (params) => {
  return defHttp.get({ url: Api.list, params });
};

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdatePosition = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 查询详情
 * @param params
 */
export const getPositionById = (params) => {
  return defHttp.get({ url: Api.get, params });
};

/**
 * 单条删除
 * @param params
 */
export const deletePosition = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 */
export const batchDeletePosition = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 批量添加黑名单
 * @param params
 */
export const batchAddBlackList = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认添加黑名单',
    content: '是否将选中数据添加至黑名单',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.addBlackList, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 批量解除黑名单
 * @param params
 */
export const batchRemoveBlackList = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认解除黑名单',
    content: '是否将选中数据移出黑名单',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.removeBlackList, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 批量添加白名单
 * @param params
 */
export const batchAddWhiteList = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认添加白名单',
    content: '是否将选中数据添加至白名单',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.addWhiteList, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 批量解除白名单
 * @param params
 */
export const batchRemoveWhiteList = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认解除白名单',
    content: '是否将选中数据移出白名单',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.removeWhiteList, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 批量挂失
 * @param params
 */
export const batchReportTheLossOfCard = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认挂失',
    content: '是否将选中数据添加至挂失卡',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.reportTheLossOfCard, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 批量解除挂失
 * @param params
 */
export const batchReleaseReportTheLossOfCard = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认解除挂失',
    content: '是否将选中数据解除挂失状态',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.releaseReportTheLossOfCard, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 自定义上传
 * @param customUpload
 */
export const customUpload = (params) => {
  defHttp.uploadFile({ url: Api.importExcel }, params);
};
